package demo.partten.filterPattern.pattern.impl;

import demo.partten.filterPattern.pattern.Person;
import demo.partten.filterPattern.pattern.Criteria;

import java.util.ArrayList;
import java.util.List;

public class OrCriteria implements Criteria{

    private List<Criteria> list;

    public OrCriteria(List<Criteria> orList) {
        list = orList;
    }


    @Override
    public List<Person> meetCriteria(List<Person> persons) {
        List<Person> result = new ArrayList<>(); // 只要符合一个条件,就会在此列表当中
        List<Person> temp = null;
        for (Criteria criteria: list) {
            temp = criteria.meetCriteria(persons);
            result.addAll(temp);
        }
        return result;
    }
}
